function unclignote(button) {
	var classOrig = button.className;

	if (classOrig.search("ack") <= 0) {//ack NON trouvé
		var newClass = classOrig + " ack";
	}
	button.setAttribute("class", newClass);
	clignote();
};

function fctDecremente(objEq) {
	var objCounter = objEq.getElementsByTagName('div')[0].getElementsByTagName('span')[0];
	objCounter.textContent = objCounter.textContent - 1;
}

function fctAck(param, eq)// change the label if the alarm is acknowledged
{
	var objParam = document.getElementById(param);
	var objCb = objParam.getElementsByTagName('input')[0];
	var objEq = document.getElementById(eq);

	if (objCb.checked) {
		var labelId = objCb.parentElement.getElementsByTagName('label')[0].id;
		var labelBtn = "#" + labelId + " span.ui-btn-text";
		$(labelBtn).text("Acknowleged");

		unclignote(objParam.getElementsByTagName('img')[0]);
		//button
		objCb.disabled = true;

		fctDecremente(objEq);
	}
};

function clignote() {
	for (var i = 0; i < document.images.length; i++) {
		var classOrig = document.images[i].className;

		if (classOrig.search("blinking") > 0) {//blinking trouvé
			path = document.images[i].src;
			//alert("i= " + i + " et path = " + path);
			if (classOrig.search("ack") <= 0) {//ack NON trouvé
				document.images[i].src = path.replace("png", "gif");
			} else {//ack trouvé
				document.images[i].src = path.replace("gif", "png");
			}
		}
	}
}



function DLParams(eName, id) {
	//alert(eName);
	//var filters = array ("clear"=> true, "Ack" => false, "Alpha" => false);
	var request = $.ajax({
		type : "POST",
		url : "./ajax/infosParams.php",
		data : {
			deviceName : eName,
			clear : "true"	,
			Ack : "false"	,
			Alpha : "false"	
		},
		dataType : "json"
	});

	request.done(function(datas) {
		var balise = '#pannelParam' + id;
		$(balise).empty();
		$.each(datas, function(i, param) {
			var msg = '<div data-role="collapsible" id="param"' +id+ '" data-position="right" data-display="overlay" data-theme="a">';

			var msg = msg + '<span><h3><img id="p"' +i+ '"status" class="buttonStatus" src="images/GreenIcon.png" align="left"/> <span class="alignTitle">' +param.name+ '</span></h3>\n';

			var msg = msg + '<p>'+param.comm+'.</p>';
			
			//	var msg = msg + '<br /><h4>13/03/2013 12:12:12</h4>';

			var msg = msg + '<br /><form><div data-role="controlgroup">';

			var msg = msg + '<input type="checkbox" name="checkbox"' + id + 'id="checkbox"' + id + 'data-mini="true" disabled checked onclick="fctAck("param"' + id + ',"eq"' + i + '")/>';

			var msg = msg + '<label id="checkbox"' +id+ '"_lab" for="checkbox"' +id+ 'data-inline="true" >Acknowleged</label>';

			var msg = msg + '</div></form>';

			var msg = msg + '</span></div>';
			$(balise).append(msg);
		}); // END EACH
	}); //END REQUEST
}

